package cn.com.zero.common.auth.security.vo;

import cn.com.zero.common.auth.security.po.AuthUserPO;
import cn.com.zero.base.vo.BaseVO;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * @author xiongxj
 * @version 1.0.0
 * @Description 提供给spring security使用的用户信息
 * @createTime 2023/3/16 14:06
 */
public class UserDetailsVO extends BaseVO implements UserDetails {

    private static final long serialVersionUID = 1010362446812140017L;
    /**
     * 用户基本信息
     */
    private AuthUserPO userInfo;

    /**
     * 用户是否未锁定: true 未锁定; false 已锁定
     */
    private Boolean accountNonLocked;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public String getPassword() {
        return userInfo.getPassword();
    }

    @Override
    public String getUsername() {
        return userInfo.getUserName();
    }

    @Override
    public boolean isAccountNonExpired() {
        return userInfo.getAccountNonExpired() == null ? false : userInfo.getAccountNonExpired();
    }

    @Override
    public boolean isAccountNonLocked() {
        return this.accountNonLocked == null ? false : this.accountNonLocked;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return userInfo.getEnabled() == null ? false : userInfo.getEnabled();
    }

    public AuthUserPO getUserInfo() {
        return userInfo;
    }

    public void setUserInfo(AuthUserPO userInfo) {
        this.userInfo = userInfo;
    }

    public void setAccountNonLocked(Boolean accountNonLocked) {
        this.accountNonLocked = accountNonLocked;
    }

}
